package base.stream;

import java.io.*;

public class InputStreamAndOutputStream {
    public static void main(String[] args) throws IOException {
        readBytes();

    }

    public static void readBytes() throws IOException {
        // 文件内容: hello
        InputStream inputStream = new FileInputStream("C:\\Temp\\test\\test.txt");
        byte[] data = new byte[2];

        int bytesRead = inputStream.read(data);
        while (bytesRead != -1) {
            for (int i = 0; i < bytesRead; i++) {
                System.out.print((char) data[i]);
            }
            System.out.println("--" + bytesRead);

            bytesRead= inputStream.read(data);
        }
        inputStream.close();

        // 输出结果
        //        he--2
        //        ll--2
        //        o--1
    }

    public static void writeBytes() throws IOException {
        OutputStream outputStream = new FileOutputStream("C:\\Temp\\test\\test.txt");
        outputStream.write("hello".getBytes());
        outputStream.flush();

    }
}
